#include <pspsdk.h>
#include "amctrl.h"

/*
 * Imports from library: ThreadManForKernel
 */
extern int sceKernelSignalSema (int arg1, int arg2);
extern int sceKernelWaitSema (int arg1, int arg2, int arg3);
extern int sceKernelCreateSema (int arg1, int arg2, int arg3, int arg4, int arg5);

/*
 * Imports from library: semaphore
 */
extern int sceUtilsBufferCopyWithRange (int arg1, int arg2, int arg3, int arg4, int arg5);

/**
 * Subroutine at address 0x00000000
 */
int sub_00000 (int arg1, int arg2, int arg3)
{
  ((int *) arg1)[3] = arg3;
  var1 = arg2 + 0x00000014;
  sp = sp + 0xFFFFFFF0;
  ((int *) arg1)[0] = 0x00000004;
  ((int *) arg1)[1] = 0x00000000;
  ((int *) arg1)[2] = 0x00000000;
  ((int *) arg1)[4] = arg2;
  ((int *) sp)[0] = ra;
  var4 = sceUtilsBufferCopyWithRange (arg1, var1, arg1, var1, 0x00000004);
  ra = ((int *) sp)[0];
  sp = sp + 0x00000010;
  return (!(var4) ? 0x00000000 : 0x80510311);
}

/**
 * Subroutine at address 0x00000054
 */
int sub_00054 (int arg1, int arg2, int arg3)
{
  ((int *) arg1)[3] = arg3;
  var1 = arg2 + 0x00000014;
  sp = sp + 0xFFFFFFF0;
  ((int *) arg1)[0] = 0x00000005;
  ((int *) arg1)[1] = 0x00000000;
  ((int *) arg1)[2] = 0x00000000;
  ((int *) arg1)[4] = arg2;
  ((int *) sp)[0] = ra;
  var4 = sceUtilsBufferCopyWithRange (arg1, var1, arg1, var1, 0x00000007);
  ra = ((int *) sp)[0];
  sp = sp + 0x00000010;
  return (!(var4) ? 0x00000000 : 0x80510311);
}

/**
 * Subroutine at address 0x000000A8
 */
int sub_000A8 (int arg1, int arg2)
{
  ((int *) arg1)[0] = 0x00000004;
  var1 = arg2 + 0x00000014;
  ((int *) arg1)[3] = 0x00000100;
  sp = sp + 0xFFFFFFF0;
  ((int *) arg1)[1] = 0x00000000;
  ((int *) arg1)[2] = 0x00000000;
  ((int *) arg1)[4] = arg2;
  ((int *) sp)[0] = ra;
  var4 = sceUtilsBufferCopyWithRange (arg1, var1, arg1, var1, 0x00000005);
  ra = ((int *) sp)[0];
  sp = sp + 0x00000010;
  return (!(var4) ? 0x00000000 : 0x80510312);
}

/**
 * Subroutine at address 0x00000100
 */
int sub_00100 (int arg1, int arg2)
{
  ((int *) arg1)[0] = 0x00000005;
  var1 = arg2 + 0x00000014;
  ((int *) arg1)[3] = 0x00000100;
  sp = sp + 0xFFFFFFF0;
  ((int *) arg1)[1] = 0x00000000;
  ((int *) arg1)[2] = 0x00000000;
  ((int *) arg1)[4] = arg2;
  ((int *) sp)[0] = ra;
  var4 = sceUtilsBufferCopyWithRange (arg1, var1, arg1, var1, 0x00000008);
  ra = ((int *) sp)[0];
  sp = sp + 0x00000010;
  return (!(var4) ? 0x00000000 : 0x80510312);
}

/**
 * Subroutine at address 0x00000158
 */
int sub_00158 (int arg1, int arg2, int arg3, int arg4)
{
  sp = sp + 0xFFFFFFF0;
  ((int *) sp)[3] = ra;
  var1 = 0x00000000;
  ((int *) sp)[2] = s2;
  var2 = arg2;
  ((int *) sp)[1] = s1;
  var3 = arg3;
  ((int *) sp)[0] = s0;
  var4 = arg1;
  while (1) {
    var5 = var4 + var1;
    var6 = ((unsigned char *) (var3 + var1))[0];
    var7 = ((unsigned char *) var5)[20];
    var1 = var1 + 0x00000001;
    ((char *) var5)[20] = (var7 ^ var6);
    if (((var1 < 0x00000010)) != 0x00000000)
      continue;
    break;
  }
  var10 = sub_00000 (var4, var2, arg4);
  ra = ((int *) sp)[3];
  if (!(var10 != 0x00000000))
  {
    var11 = 0x00000000;
    while (1) {
      var12 = ((unsigned char *) ((var4 + var2) + var11))[4];
      var11 = var11 + 0x00000001;
      ((char *) (var3 + var11))[0] = var12;
      if (((var11 < 0x00000010)) != 0x00000000)
        continue;
      break;
    }
    var10 = 0x00000000;
    ra = ((int *) sp)[3];
  }
  var13 = ((int *) sp)[2];
  var14 = ((int *) sp)[1];
  var15 = ((int *) sp)[0];
  sp = sp + 0x00000010;
  return var10;
}

/**
 * Subroutine at address 0x000001F8
 */
int sub_001F8 (int arg1, int arg2, int arg3, int arg4)
{
  sp = sp + 0xFFFFFFE0;
  ((int *) sp)[6] = ra;
  var1 = 0x00000000;
  ((int *) sp)[5] = s1;
  var2 = arg3;
  ((int *) sp)[4] = s0;
  var3 = arg1;
  while (1) {
    var4 = ((unsigned char *) ((arg1 + arg2) + var1))[4];
    var5 = sp + var1;
    var1 = var1 + 0x00000001;
    ((char *) var5)[0] = var4;
    if (((var1 < 0x00000010)) != 0x00000000)
      continue;
    break;
  }
  var8 = sub_00054 (var3, arg2, arg4);
  ra = ((int *) sp)[6];
  if (!(var8 != 0x00000000))
  {
    var9 = 0x00000000;
    while (1) {
      var10 = var3 + var9;
      var11 = ((unsigned char *) (var2 + var9))[0];
      var12 = ((unsigned char *) var10)[0];
      var9 = var9 + 0x00000001;
      ((char *) var10)[0] = (var12 ^ var11);
      if (((var9 < 0x00000010)) != 0x00000000)
        continue;
      break;
    }
    var13 = 0x00000000;
    while (1) {
      var14 = sp + var13;
      var15 = ((unsigned char *) var14)[0];
      var13 = var13 + 0x00000001;
      ((char *) (var2 + var13))[0] = var15;
      if (((var13 < 0x00000010)) != 0x00000000)
        continue;
      break;
    }
    var8 = 0x00000000;
    ra = ((int *) sp)[6];
  }
  var16 = ((int *) sp)[5];
  var17 = ((int *) sp)[4];
  sp = sp + 0x00000020;
  return var8;
}

/**
 * Subroutine at address 0x000003F0
 */
int sub_003F0 ()
{
  sp = sp + 0xFFFFFFF0;
  ((int *) sp)[0] = ra;
  var3 = sceUtilsBufferCopyWithRange (arg1, 0x00000014, 0x00000000, 0x00000000, 0x0000000E);
  ra = ((int *) sp)[0];
  sp = sp + 0x00000010;
  return (!(var3) ? 0x00000000 : 0x80510315);
}

/**
 * Subroutine at address 0x00000428
 */
int sub_00428 (int arg1, int arg2, int arg3, int arg4, int arg5, int arg6)
{
  sp = sp + 0xFFFFFFC0;
  ((int *) sp)[12] = ra;
  ((int *) sp)[11] = s3;
  var1 = 0x00000000;
  ((int *) sp)[10] = s2;
  var2 = arg3;
  ((int *) sp)[9] = s1;
  var3 = arg5;
  ((int *) sp)[8] = s0;
  var4 = arg1;
  while (1) {
    var5 = ((unsigned char *) (arg4 + var1))[0];
    var1 = var1 + 0x00000001;
    ((char *) (var4 + var1))[20] = var5;
    if (((var1 < 0x00000010)) != 0x00000000)
      continue;
    break;
  }
  var6 = 0x00000000;
  if (arg6 == 0x00000002)
  {
    while (1) {
      var52 = var4 + var6;
      var53 = ((unsigned char *) (var6 + 0x0000151C))[0];
      var54 = ((unsigned char *) var52)[20];
      var6 = var6 + 0x00000001;
      ((char *) var52)[20] = (var54 ^ var53);
      if (((var6 < 0x00000010)) != 0x00000000)
        continue;
      break;
    }
    var57 = sub_00100 (var4, 0x00000010);
    var13 = var57;
    var58 = 0x00000000;
    while (1) {
      var59 = var4 + var58;
      var60 = ((unsigned char *) (var58 + 0x0000150C))[0];
      var61 = ((unsigned char *) var59)[0];
      var58 = var58 + 0x00000001;
      ((char *) var59)[0] = (var61 ^ var60);
      if (((var58 < 0x00000010)) != 0x00000000)
        continue;
      break;
    }
  }
  else
  {
    while (1) {
      var7 = var4 + var6;
      var8 = ((unsigned char *) (var6 + 0x0000151C))[0];
      var9 = ((unsigned char *) var7)[20];
      var6 = var6 + 0x00000001;
      ((char *) var7)[20] = (var9 ^ var8);
      if (((var6 < 0x00000010)) != 0x00000000)
        continue;
      break;
    }
    var12 = sub_00054 (var4, 0x00000010, 0x00000039);
    var13 = var12;
    var14 = 0x00000000;
    while (1) {
      var15 = var4 + var14;
      var16 = ((unsigned char *) (var14 + 0x0000150C))[0];
      var17 = ((unsigned char *) var15)[0];
      var14 = var14 + 0x00000001;
      ((char *) var15)[0] = (var17 ^ var16);
      if (((var14 < 0x00000010)) != 0x00000000)
        continue;
      break;
    }
  }
  ra = ((int *) sp)[12];
  if (!(var13 != 0x00000000))
  {
    var18 = 0x00000000;
    var19 = sp + 0x00000010;
    while (1) {
      var20 = ((unsigned char *) (var4 + var18))[0];
      var18 = var18 + 0x00000001;
      ((char *) (var19 + var18))[0] = var20;
      if (((var18 < 0x00000010)) != 0x00000000)
        continue;
      break;
    }
    var21 = ((int *) var3)[0];
    var22 = 0x00000000;
    if (var21 == 0x00000001)
    {
      var50 = 0x00000000;
      while (1) {
        var51 = sp + var50;
        var50 = var50 + 0x00000001;
        ((char *) var51)[0] = 0x00000000;
        if (((var50 < 0x00000010)) != 0x00000000)
          continue;
        break;
      }
    }
    else
    {
      while (1) {
        var23 = ((unsigned char *) (var19 + var22))[0];
        var24 = sp + var22;
        var22 = var22 + 0x00000001;
        ((char *) var24)[0] = var23;
        if (((var22 < 0x0000000C)) != 0x00000000)
          continue;
        break;
      }
      var25 = ((unsigned char *) var3)[0];
      var26 = var21 + 0xFFFFFFFF;
      ((char *) sp)[12] = (var25 + 0xFFFFFFFF);
      ((char *) sp)[13] = (var26 >> 0x00000008);
      ((char *) sp)[14] = (var26 >> 0x00000010);
      ((char *) sp)[15] = (var26 >> 0x00000018);
    }
    var28 = var2 + 0x00000014;
    var29 = var4;
    if (!(((0x00000014 < var28)) == 0x00000000))
    {
      while (1) {
        var30 = 0x00000000;
        var31 = var4 + var27;
        while (1) {
          var32 = ((unsigned char *) (var19 + var30))[0];
          var30 = var30 + 0x00000001;
          ((char *) (var31 + var30))[0] = var32;
          if (((var30 < 0x0000000C)) != 0x00000000)
            continue;
          break;
        }
        var33 = ((unsigned char *) var3)[0];
        var27 = var27 + 0x00000010;
        ((char *) var31)[12] = var33;
        var34 = ((int *) var3)[0];
        ((char *) var31)[13] = (var34 >> 0x00000008);
        var35 = ((unsigned short *) var3)[1];
        ((char *) var31)[14] = var35;
        var36 = ((unsigned char *) var3)[3];
        ((char *) var31)[15] = var36;
        var37 = ((int *) var3)[0];
        ((int *) var3)[0] = (var37 + 0x00000001);
        if (((var27 < var28)) != 0x00000000)
          continue;
        break;
      }
      var29 = var4;
    }
    var38 = sp;
    var41 = sub_001F8 (var29, var2, var38, 0x00000063);
    var13 = var41;
    if (!(var41 != 0x00000000))
    {
      var42 = 0x00000000;
      if (!(((var41 < var2)) == 0x00000000))
      {
        while (1) {
          var43 = arg2 + var42;
          var44 = ((unsigned char *) (var4 + var42))[0];
          var45 = ((unsigned char *) var43)[0];
          var42 = var42 + 0x00000001;
          ((char *) var43)[0] = (var45 ^ var44);
          if (((var42 < var2)) != 0x00000000)
            continue;
          break;
        }
      }
      var13 = 0x00000000;
    }
    ra = ((int *) sp)[12];
  }
  var46 = ((int *) sp)[11];
  var47 = ((int *) sp)[10];
  var48 = ((int *) sp)[9];
  var49 = ((int *) sp)[8];
  sp = sp + 0x00000040;
  return var13;
}

/**
 * Subroutine at address 0x000006DC
 */
void module_start ()
{
  sp = sp + 0xFFFFFFF0;
  ((int *) sp)[0] = ra;
  var3 = sceKernelCreateSema ("SceAmctrl", 0x00000000, 0x00000001, 0x00000001, 0x00000000);
  ra = ((int *) sp)[0];
  *((int *) 0x00001D94) = var3;
  sp = sp + 0x00000010;
  return;
}

/**
 * Subroutine at address 0x0000071C
 */
void sceDrmBBMacInit (int arg1, int arg2)
{
  ((int *) arg1)[0] = arg2;
  var1 = 0x00000000;
  while (1) {
    var1 = var1 + 0x00000001;
    ((char *) (arg1 + var1))[4] = 0x00000000;
    if (((var1 < 0x00000010)) != 0x00000000)
      continue;
    break;
  }
  var2 = 0x00000000;
  var3 = arg1 + 0x00000014;
  while (1) {
    var2 = var2 + 0x00000001;
    ((char *) var3)[0] = 0x00000000;
    var3 = var3 + 0x00000001;
    if (((var2 < 0x00000010)) != 0x00000000)
      continue;
    break;
  }
  ((int *) arg1)[9] = 0x00000000;
  return;
}

/**
 * Subroutine at address 0x00000760
 */
void sceDrmBBMacUpdate (int arg1, int arg2, int arg3)
{
  sp = sp + 0xFFFFFFD0;
  ((int *) sp)[2] = s2;
  var1 = arg1;
  var2 = *((int *) 0x00001D94);
  ((int *) sp)[4] = s4;
  var3 = arg2;
  ((int *) sp)[1] = s1;
  var4 = arg3;
  ((int *) sp)[0] = s0;
  ((int *) sp)[9] = ra;
  ((int *) sp)[8] = fp;
  ((int *) sp)[7] = s7;
  ((int *) sp)[6] = s6;
  ((int *) sp)[5] = s5;
  ((int *) sp)[3] = s3;
  var7 = sceKernelWaitSema (var2, 0x00000001, 0x00000000);
  if (var7 != 0x00000000)
  {
  }
  else
  {
    var8 = ((int *) var1)[9];
    var9 = 0x80510302;
    if (((var8 < 0x00000011)) == 0x00000000)
    {

    label33:
    }
    else
    {
      if ((((var8 + var4) < 0x00000011)) != 0x00000000)
      {
        var45 = 0x00000000;
        if (!(var4 == 0x00000000))
        {
          while (1) {
            var46 = ((unsigned char *) (var3 + var45))[0];
            var45 = var45 + 0x00000001;
            ((char *) ((var1 + var8) + var45))[20] = var46;
            if (((var45 < var4)) == 0x00000000)
              break;
            var8 = ((int *) var1)[9];
            continue;
          }
          var8 = ((int *) var1)[9];
        }
        var9 = 0x00000000;
        ((int *) var1)[9] = (var8 + var4);
        goto label33;
      }
      else
      {
        var10 = ((int *) var1)[0];
        var11 = ((var10 ^ 0x00000002)) ? 0x00000038 : 0x0000003A;
        var12 = 0x00000000;
        if (!(var8 == 0x00000000))
        {
          var13 = var1 + 0x00000014;
          while (1) {
            var14 = *((int *) 0x00001544);
            var15 = ((unsigned char *) var13)[0];
            ((char *) (var14 + var12))[0] = var15;
            var12 = var12 + 0x00000001;
            var8 = ((int *) var1)[9];
            var13 = var13 + 0x00000001;
            if (((var12 < var8)) != 0x00000000)
              continue;
            break;
          }
        }
        var16 = (var8 + var4) & 0x0000000F;
        var17 = !(var16) ? 0x00000010 : var16;
        var18 = var8;
        ((int *) var1)[9] = var17;
        var19 = var4 - var17;
        var20 = 0x00000000;
        if (!(var17 == 0x00000000))
        {
          var21 = var1 + 0x00000014;
          while (1) {
            var22 = ((unsigned char *) ((var3 + var19) + var20))[0];
            var20 = var20 + 0x00000001;
            ((char *) var21)[0] = var22;
            var21 = var21 + 0x00000001;
            if (((var20 < var17)) != 0x00000000)
              continue;
            break;
          }
        }
        var23 = 0x00000000;
        if (var19 == 0x00000000)
        {

        label27:
          if (var18 != 0x00000000)
          {
            var41 = sub_00158 (0x00001580, var18, (var1 + 0x00000004), var11);
            var9 = var41;
            if (var41 == 0x00000000)
            {

            label32:
              var9 = 0x00000000;
              goto label33;
            }
            else
            {
            }
          }
          else
          goto label32;
        }
        else
        {
          while (1) {
            if (var18 == 0x00000800)
            {
              var44 = sub_00158 (0x00001580, 0x00000800, (var1 + 0x00000004), var11);
              var9 = var44;
              if (var44 != 0x00000000)
                break;
              var18 = 0x00000000;

            label26:
              var24 = *((int *) 0x00001544);
              var25 = ((unsigned char *) (var3 + var23))[0];
              var23 = var23 + 0x00000001;
              var18 = var18 + 0x00000001;
              ((char *) (var24 + var18))[0] = var25;
              if (((var23 < var19)) != 0x00000000)
                continue;
              goto label27;
            }
            else
            goto label26;
            goto label34;
          }
          goto label33;
        }
      }
    }

  label34:
    var26 = *((int *) 0x00001D94);
    var29 = sceKernelSignalSema (var26, 0x00000001);
  }
  ra = ((int *) sp)[9];
  var30 = ((int *) sp)[8];
  var31 = ((int *) sp)[7];
  var32 = ((int *) sp)[6];
  var33 = ((int *) sp)[5];
  var34 = ((int *) sp)[4];
  var35 = ((int *) sp)[3];
  var36 = ((int *) sp)[2];
  var37 = ((int *) sp)[1];
  var38 = ((int *) sp)[0];
  sp = sp + 0x00000030;
  return;
}

/**
 * Subroutine at address 0x00000998
 */
int sceDrmBBMacFinal (int arg1, int arg2, int arg3)
{
  sp = sp + 0xFFFFFFB0;
  ((int *) sp)[10] = s2;
  var1 = arg1;
  var2 = *((int *) 0x00001D94);
  ((int *) sp)[13] = s5;
  ((int *) sp)[12] = s4;
  var3 = arg3;
  ((int *) sp)[8] = s0;
  ((int *) sp)[17] = ra;
  ((int *) sp)[16] = fp;
  ((int *) sp)[15] = s7;
  ((int *) sp)[14] = s6;
  ((int *) sp)[11] = s3;
  ((int *) sp)[9] = s1;
  var6 = sceKernelWaitSema (var2, 0x00000001, 0x00000000);
  if (var6 != 0x00000000)
  {
    var78 = 0x80000041;
  }
  else
  {
    var7 = ((int *) var1)[9];
    var8 = 0x80510302;
    if (!(((var7 < 0x00000011)) == 0x00000000))
    {
      var9 = ((int *) var1)[0];
      var10 = ((var9 ^ 0x00000002)) ? 0x00000038 : 0x0000003A;
      var11 = 0x00000000;
      while (1) {
        var12 = *((int *) 0x00001544);
        var11 = var11 + 0x00000001;
        ((char *) (var12 + var11))[0] = 0x00000000;
        if (((var11 < 0x00000010)) != 0x00000000)
          continue;
        break;
      }
      var15 = sub_00000 (0x00001580, 0x00000010, var10);
      var8 = var15;
      if (!(var15 != 0x00000000))
      {
        var16 = *((int *) 0x00001544);
        var17 = 0x00000000;
        while (1) {
          var18 = ((unsigned char *) (var16 + var17))[0];
          var19 = sp + var17;
          var17 = var17 + 0x00000001;
          ((char *) var19)[0] = var18;
          if (((var17 < 0x00000010)) != 0x00000000)
            continue;
          break;
        }
        var20 = ((char *) sp)[0];
        var21 = 0x00000000;
        while (1) {
          var22 = sp + var21;
          var23 = ((unsigned char *) var22)[0];
          var24 = ((unsigned char *) var22)[1];
          var21 = var21 + 0x00000001;
          ((char *) var22)[0] = ((var24 >> 0x00000007) | (var23 << 0x00000001));
          if (((var21 < 0x0000000F)) != 0x00000000)
            continue;
          break;
        }
        var25 = ((unsigned char *) sp)[15];
        var26 = ((int *) var1)[9];
        ((char *) sp)[15] = (((((var20 < 0x00000000))) ? 0x00000087 : 0x00000000) ^ (var25 << 0x00000001));
        if (!(var26 == 0x00000010))
        {
          var27 = ((char *) sp)[0];
          var28 = 0x00000000;
          while (1) {
            var29 = sp + var28;
            var30 = ((unsigned char *) var29)[0];
            var31 = ((unsigned char *) var29)[1];
            var28 = var28 + 0x00000001;
            ((char *) var29)[0] = ((var31 >> 0x00000007) | (var30 << 0x00000001));
            if (((var28 < 0x0000000F)) != 0x00000000)
              continue;
            break;
          }
          var32 = ((unsigned char *) sp)[15];
          var33 = var26 + 0x00000001;
          ((char *) sp)[15] = (((((var27 < 0x00000000))) ? 0x00000087 : 0x00000000) ^ (var32 << 0x00000001));
          ((char *) (var26 + var1))[20] = 0xFFFFFF80;
          if (!(((var33 < 0x00000010)) == 0x00000000))
          {
            var34 = (var33 + var1) + 0x00000014;
            while (1) {
              var33 = var33 + 0x00000001;
              ((char *) var34)[0] = 0x00000000;
              var34 = var34 + 0x00000001;
              if (((var33 < 0x00000010)) != 0x00000000)
                continue;
              break;
            }
          }
        }
        var35 = 0x00000000;
        var36 = var1 + 0x00000010;
        while (1) {
          var37 = sp + var35;
          var38 = ((unsigned char *) var37)[0];
          var39 = ((unsigned char *) var36)[4];
          var35 = var35 + 0x00000001;
          ((char *) var36)[4] = (var39 ^ var38);
          var36 = var36 + 0x00000001;
          if (((var35 < 0x00000010)) != 0x00000000)
            continue;
          break;
        }
        var40 = 0x00000000;
        var41 = var1 + 0x00000014;
        while (1) {
          var42 = *((int *) 0x00001544);
          var43 = ((unsigned char *) var41)[0];
          var41 = var41 + 0x00000001;
          var40 = var40 + 0x00000001;
          ((char *) (var42 + var40))[0] = var43;
          if (((var40 < 0x00000010)) != 0x00000000)
            continue;
          break;
        }
        var44 = 0x00000000;
        var45 = sp + 0x00000010;
        while (1) {
          var46 = ((unsigned char *) (var1 + var44))[4];
          var44 = var44 + 0x00000001;
          ((char *) (var45 + var44))[0] = var46;
          if (((var44 < 0x00000010)) != 0x00000000)
            continue;
          break;
        }
        var49 = sub_00158 (0x00001580, 0x00000010, var45, var10);
        var8 = var49;
        if (!(var49 != 0x00000000))
        {
          var50 = 0x00000000;
          while (1) {
            var51 = var45 + var50;
            var52 = ((unsigned char *) (var50 + 0x000014FC))[0];
            var53 = ((unsigned char *) var51)[0];
            var50 = var50 + 0x00000001;
            ((char *) var51)[0] = (var53 ^ var52);
            if (((var50 < 0x00000010)) != 0x00000000)
              continue;
            break;
          }
          var54 = ((int *) var1)[0];
          var55 = 0x00000000;
          if (var54 == 0x00000002)
          {
            while (1) {
              var88 = *((int *) 0x00001544);
              var89 = ((unsigned char *) (var45 + var55))[0];
              var55 = var55 + 0x00000001;
              ((char *) (var88 + var55))[0] = var89;
              if (((var55 < 0x00000010)) != 0x00000000)
                continue;
              break;
            }
            var92 = sub_000A8 (0x00001580, 0x00000010);
            var8 = var92;
            if (!(var92 != 0x00000000))
            {
              var95 = sub_00000 (0x00001580, 0x00000010, var10);
              var8 = var95;
              if (!(var95 != 0x00000000))
              {
                var96 = *((int *) 0x00001544);
                var97 = 0x00000000;
                while (1) {
                  var98 = ((unsigned char *) (var96 + var97))[0];
                  var97 = var97 + 0x00000001;
                  ((char *) (var45 + var97))[0] = var98;
                  if (((var97 < 0x00000010)) != 0x00000000)
                    continue;
                  break;
                }

              label44:
                var56 = 0x00000000;
                if (var3 == 0x00000000)
                {

                  label55:
                  while (1) {
                    var70 = ((unsigned char *) (var45 + var56))[0];
                    var56 = var56 + 0x00000001;
                    ((char *) (arg2 + var56))[0] = var70;
                    if (((var56 < 0x00000010)) != 0x00000000)
                      continue;
                    break;
                  }
                  var71 = 0x00000000;
                  while (1) {
                    var71 = var71 + 0x00000001;
                    ((char *) (var1 + var71))[4] = 0x00000000;
                    if (((var71 < 0x00000010)) != 0x00000000)
                      continue;
                    break;
                  }
                  var72 = 0x00000000;
                  var73 = var1 + 0x00000014;
                  while (1) {
                    var72 = var72 + 0x00000001;
                    ((char *) var73)[0] = 0x00000000;
                    var73 = var73 + 0x00000001;
                    if (((var72 < 0x00000010)) != 0x00000000)
                      continue;
                    break;
                  }
                  ((int *) var1)[9] = 0x00000000;
                  var8 = 0x00000000;
                  ((int *) var1)[0] = 0x00000000;
                }
                else
                {
                  var57 = 0x00000000;
                  while (1) {
                    var58 = var45 + var57;
                    var59 = ((unsigned char *) (var3 + var57))[0];
                    var60 = ((unsigned char *) var58)[0];
                    var57 = var57 + 0x00000001;
                    ((char *) var58)[0] = (var60 ^ var59);
                    if (((var57 < 0x00000010)) != 0x00000000)
                      continue;
                    break;
                  }
                  var61 = 0x00000000;
                  while (1) {
                    var62 = *((int *) 0x00001544);
                    var63 = ((unsigned char *) (var45 + var61))[0];
                    var61 = var61 + 0x00000001;
                    ((char *) (var62 + var61))[0] = var63;
                    if (((var61 < 0x00000010)) != 0x00000000)
                      continue;
                    break;
                  }
                  var66 = sub_00000 (0x00001580, 0x00000010, var10);
                  var8 = var66;
                  if (!(var66 != 0x00000000))
                  {
                    var67 = *((int *) 0x00001544);
                    var68 = 0x00000000;
                    while (1) {
                      var69 = ((unsigned char *) (var67 + var68))[0];
                      var68 = var68 + 0x00000001;
                      ((char *) (var45 + var68))[0] = var69;
                      if (((var68 < 0x00000010)) != 0x00000000)
                        continue;
                      break;
                    }
                    var56 = 0x00000000;
                    goto label55;
                  }
                }
              }
            }
          }
          else
          goto label44;
        }
      }
    }
    var74 = *((int *) 0x00001D94);
    var77 = sceKernelSignalSema (var74, 0x00000001);
    var78 = ((var77) ? 0x80000041 : var8);
  }
  ra = ((int *) sp)[17];
  var79 = ((int *) sp)[16];
  var80 = ((int *) sp)[15];
  var81 = ((int *) sp)[14];
  var82 = ((int *) sp)[13];
  var83 = ((int *) sp)[12];
  var84 = ((int *) sp)[11];
  var85 = ((int *) sp)[10];
  var86 = ((int *) sp)[9];
  var87 = ((int *) sp)[8];
  sp = sp + 0x00000050;
  return var78;
}

/**
 * Subroutine at address 0x00000DEC
 */
void sceDrmBBMacFinal2 (int arg1, int arg2, int arg3)
{
  sp = sp + 0xFFFFFFD0;
  ((int *) sp)[5] = s1;
  var1 = arg2;
  var2 = sp;
  ((int *) sp)[4] = s0;
  ((int *) sp)[8] = ra;
  ((int *) sp)[7] = s3;
  ((int *) sp)[6] = s2;
  var3 = ((int *) arg1)[0];
  var6 = sceDrmBBMacFinal (arg1, var2, arg3);
  var7 = var6;
  if (!(var6 != 0x00000000))
  {
    var8 = *((int *) 0x00001D94);
    var11 = sceKernelWaitSema (var8, 0x00000001, 0x00000000);
    var7 = 0x80000041;
    if (!(var11 != 0x00000000))
    {
      var12 = 0x00000000;
      if (var3 == 0x00000003)
      {
        while (1) {
          var30 = *((int *) 0x00001544);
          var31 = ((unsigned char *) (var1 + var12))[0];
          var12 = var12 + 0x00000001;
          ((char *) (var30 + var12))[0] = var31;
          if (((var12 < 0x00000010)) != 0x00000000)
            continue;
          break;
        }
        var34 = sub_00054 (0x00001580, 0x00000010, 0x00000063);
        var21 = var34;
        if (var34 == 0x00000000)
        {

        label16:
          var15 = *((int *) 0x00001540);
          var16 = sp;
          var17 = 0x00000000;
          var18 = 0x00000000;
          var19 = ((char *) var16)[0];
          while (1) {
            var20 = ((char *) var15)[0];
            var18 = var18 + 0x00000001;
            var16 = var16 + 0x00000001;
            var15 = var15 + 0x00000001;
            if (var19 != var20)
            {
              var17 = var19 - var20;
            }
            else
            {
              if (!(((var18 < 0x00000010)) != 0x00000000))
                break;
              var19 = ((char *) var16)[0];
              continue;
            }
          }
          var21 = (!(var17) ? 0x00000000 : 0x80510300);
          var22 = *((int *) 0x00001D94);
        }
        else
        {
          var35 = *((int *) 0x00001D94);
        }
      }
      else
      {
        while (1) {
          var13 = *((int *) 0x00001540);
          var14 = ((unsigned char *) (var1 + var12))[0];
          var12 = var12 + 0x00000001;
          ((char *) (var13 + var12))[0] = var14;
          if (((var12 < 0x00000010)) != 0x00000000)
            continue;
          break;
        }
        goto label16;
      }
      var25 = sceKernelSignalSema (var22, 0x00000001);
      var7 = (var25) ? 0x80000041 : var21;
    }
  }
  ra = ((int *) sp)[8];
  var26 = ((int *) sp)[7];
  var27 = ((int *) sp)[6];
  var28 = ((int *) sp)[5];
  var29 = ((int *) sp)[4];
  sp = sp + 0x00000030;
  return;
}

/**
 * Subroutine at address 0x00000F3C
 */
void sceDrmBBCipherInit (int arg1, int arg2, int arg3, int arg4, int arg5, int arg6)
{
  sp = sp + 0xFFFFFFD0;
  ((int *) sp)[7] = s7;
  ((int *) sp)[2] = s2;
  var1 = arg1;
  var2 = *((int *) 0x00001D94);
  ((int *) sp)[4] = s4;
  ((int *) sp)[0] = s0;
  var3 = arg3;
  ((int *) sp)[6] = s6;
  var4 = arg4;
  ((int *) sp)[5] = s5;
  var5 = arg5;
  ((int *) sp)[3] = s3;
  ((int *) sp)[1] = s1;
  ((int *) sp)[8] = ra;
  var6 = 0x80000041;
  var9 = sceKernelWaitSema (var2, 0x00000001, 0x00000000);
  if (var9 != 0x00000000)
  {
  }
  else
  {
    ((int *) var1)[0] = arg2;
    if (var3 == 0x00000002)
    {
      ((int *) var1)[1] = (arg6 + 0x00000001);
      var72 = 0x00000000;
      while (1) {
        var73 = ((unsigned char *) (var4 + var72))[0];
        var72 = var72 + 0x00000001;
        ((char *) (var1 + var72))[8] = var73;
        if (((var72 < 0x00000010)) != 0x00000000)
          continue;
        break;
      }
      var74 = 0x00000000;
      if (var5 == 0x00000000)
      {

      label42:
        var10 = 0x00000000;
      }
      else
      {
        while (1) {
          var75 = var1 + var74;
          var76 = ((unsigned char *) (var5 + var74))[0];
          var77 = ((unsigned char *) var75)[8];
          var74 = var74 + 0x00000001;
          ((char *) var75)[8] = (var77 ^ var76);
          if (((var74 < 0x00000010)) != 0x00000000)
            continue;
          break;
        }
        var10 = 0x00000000;
      }
    }
    else
    {
      if (!(var3 == 0x00000001))
        goto label42;
      ((int *) var1)[1] = var3;
      var23 = *((int *) 0x0000154C);
      var26 = sub_003F0 ();
      var10 = var26;
      if (!(var26 != 0x00000000))
      {
        var27 = 0x0000000F;
        while (1) {
          var28 = *((int *) 0x0000154C);
          var29 = var28 + var27;
          var30 = ((unsigned char *) var29)[0];
          var27 = var27 + 0xFFFFFFFF;
          ((char *) var29)[20] = var30;
          if (var27 >= 0)
            continue;
          break;
        }
        var31 = 0x00000000;
        while (1) {
          var32 = *((int *) 0x0000154C);
          var31 = var31 + 0x00000001;
          ((char *) (var32 + var31))[32] = 0x00000000;
          if (((var31 < 0x00000004)) != 0x00000000)
            continue;
          break;
        }
        var33 = ((int *) var1)[0];
        if (var33 == 0x00000002)
        {
          var58 = 0x00000000;
          while (1) {
            var59 = *((int *) 0x00001550);
            var60 = ((unsigned char *) (var58 + 0x0000150C))[0];
            var61 = var59 + var58;
            var62 = ((unsigned char *) var61)[0];
            var58 = var58 + 0x00000001;
            ((char *) var61)[0] = (var62 ^ var60);
            if (((var58 < 0x00000010)) != 0x00000000)
              continue;
            break;
          }
          var63 = *((int *) 0x00001548);
          var66 = sub_000A8 (var63, 0x00000010);
          var10 = var66;
          var67 = 0x00000000;
          while (1) {
            var68 = *((int *) 0x00001550);
            var69 = ((unsigned char *) (var67 + 0x0000151C))[0];
            var70 = var68 + var67;
            var71 = ((unsigned char *) var70)[0];
            var67 = var67 + 0x00000001;
            ((char *) var70)[0] = (var71 ^ var69);
            if (((var67 < 0x00000010)) != 0x00000000)
              continue;
            break;
          }
        }
        else
        {
          var34 = 0x00000000;
          while (1) {
            var35 = *((int *) 0x00001550);
            var36 = ((unsigned char *) (var34 + 0x0000150C))[0];
            var37 = var35 + var34;
            var38 = ((unsigned char *) var37)[0];
            var34 = var34 + 0x00000001;
            ((char *) var37)[0] = (var38 ^ var36);
            if (((var34 < 0x00000010)) != 0x00000000)
              continue;
            break;
          }
          var39 = *((int *) 0x00001548);
          var42 = sub_00000 (var39, 0x00000010, 0x00000039);
          var10 = var42;
          var43 = 0x00000000;
          while (1) {
            var44 = *((int *) 0x00001550);
            var45 = ((unsigned char *) (var43 + 0x0000151C))[0];
            var46 = var44 + var43;
            var47 = ((unsigned char *) var46)[0];
            var43 = var43 + 0x00000001;
            ((char *) var46)[0] = (var47 ^ var45);
            if (((var43 < 0x00000010)) != 0x00000000)
              continue;
            break;
          }
        }
        var48 = 0x00000000;
        if (!(var10 != 0x00000000))
        {
          while (1) {
            var49 = *((int *) 0x00001550);
            var50 = ((unsigned char *) (var49 + var48))[0];
            var48 = var48 + 0x00000001;
            ((char *) (var1 + var48))[8] = var50;
            if (((var48 < 0x00000010)) != 0x00000000)
              continue;
            break;
          }
          var51 = 0x00000000;
          while (1) {
            var52 = *((int *) 0x00001550);
            var53 = ((unsigned char *) (var52 + var51))[0];
            var51 = var51 + 0x00000001;
            ((char *) (var4 + var51))[0] = var53;
            if (((var51 < 0x00000010)) != 0x00000000)
              continue;
            break;
          }
          var54 = 0x00000000;
          if (var5 == 0x00000000)
            goto label42;
          while (1) {
            var55 = var1 + var54;
            var56 = ((unsigned char *) (var5 + var54))[0];
            var57 = ((unsigned char *) var55)[8];
            var54 = var54 + 0x00000001;
            ((char *) var55)[8] = (var57 ^ var56);
            if (((var54 < 0x00000010)) != 0x00000000)
              continue;
            break;
          }
          var10 = 0x00000000;
        }
      }
    }
    var11 = *((int *) 0x00001D94);
    var14 = sceKernelSignalSema (var11, 0x00000001);
    var6 = (var14) ? 0x80000041 : var10;
  }
  ra = ((int *) sp)[8];
  var15 = ((int *) sp)[7];
  var16 = ((int *) sp)[6];
  var17 = ((int *) sp)[5];
  var18 = ((int *) sp)[4];
  var19 = ((int *) sp)[3];
  var20 = ((int *) sp)[2];
  var21 = ((int *) sp)[1];
  var22 = ((int *) sp)[0];
  sp = sp + 0x00000030;
  return;
}

/**
 * Subroutine at address 0x0000123C
 */
void sceDrmBBCipherUpdate (int arg1, int arg2, int arg3)
{
  sp = sp + 0xFFFFFFD0;
  ((int *) sp)[8] = fp;
  ((int *) sp)[6] = s6;
  var1 = arg2;
  ((int *) sp)[3] = s3;
  var2 = arg1;
  ((int *) sp)[1] = s1;
  var3 = arg3;
  ((int *) sp)[0] = s0;
  ((int *) sp)[9] = ra;
  ((int *) sp)[7] = s7;
  ((int *) sp)[5] = s5;
  ((int *) sp)[4] = s4;
  ((int *) sp)[2] = s2;
  var4 = *((int *) 0x00001D94);
  var7 = sceKernelWaitSema (var4, 0x00000001, 0x00000000);
  if (var7 != 0x00000000)
  {
  }
  else
  {
    var8 = 0x00000000;
    if (var3 == 0x00000000)
    {

    label20:
      var15 = *((int *) 0x00001D94);
    }
    else
    {
      var8 = 0x80510301;
      if ((var3 & 0x0000000F) != 0x00000000)
        goto label20;
      var9 = 0x00000000;
      if (((var3 < 0x00000800)) != 0x00000000)
      {

      label14:
        if (var3 != 0x00000000)
        {
          var28 = *((int *) 0x00001548);
          var29 = ((int *) var2)[0];
          var32 = sub_00428 (var28, (var1 + var9), var3, (var2 + 0x00000008), (var2 + 0x00000004), var29);
          var8 = var32;
          if (var32 == 0x00000000)
          {

          label19:
            var8 = 0x00000000;
            goto label20;
          }
          else
          {
            var33 = *((int *) 0x00001D94);
          }
        }
        else
        goto label19;
      }
      else
      {
        var10 = *((int *) 0x00001548);
        while (1) {
          var11 = ((int *) var2)[0];
          var14 = sub_00428 (var10, (var1 + var9), 0x00000800, (var2 + 0x00000008), (var2 + 0x00000004), var11);
          var3 = var3 + 0xFFFFF800;
          var8 = var14;
          var9 = var9 + 0x00000800;
          if (var8 != 0x00000000)
            break;
          var10 = *((int *) 0x00001548);
          if (((var3 < 0x00000800)) == 0x00000000)
            continue;
          goto label14;
        }
        goto label20;
      }
    }
    var18 = sceKernelSignalSema (var15, 0x00000001);
  }
  ra = ((int *) sp)[9];
  var19 = ((int *) sp)[8];
  var20 = ((int *) sp)[7];
  var21 = ((int *) sp)[6];
  var22 = ((int *) sp)[5];
  var23 = ((int *) sp)[4];
  var24 = ((int *) sp)[3];
  var25 = ((int *) sp)[2];
  var26 = ((int *) sp)[1];
  var27 = ((int *) sp)[0];
  sp = sp + 0x00000030;
  return;
}

/**
 * Subroutine at address 0x00001384
 */
void sceDrmBBCipherFinal (int arg1)
{
  var1 = 0x00000000;
  while (1) {
    var1 = var1 + 0x00000001;
    ((char *) (arg1 + var1))[8] = 0x00000000;
    if (((var1 < 0x00000010)) != 0x00000000)
      continue;
    break;
  }
  ((int *) arg1)[1] = 0x00000000;
  ((int *) arg1)[0] = 0x00000000;
  return;
}

